package com.framework.web.bus.repository.specifications;

import com.framework.core.util.LikePatternUtil;
import com.framework.core.util.StringUtil;
import com.framework.web.bus.domain.Commentinfo;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
* @Title: Specs
* @Description: 分页查询
* @author laowang
* @date 2016-09-07
* @version V1.0
*
*/
public class CommentinfoSpecs {

/**
* 分页查询
*
* @param  commentinfo
* @return
*/
public static Specification<Commentinfo> pageQueryCommentinfo(
final Commentinfo  commentinfo) {

return new Specification<Commentinfo>() {
@Override
public Predicate toPredicate(Root<Commentinfo> root,
CriteriaQuery<?> query, CriteriaBuilder builder) {
    Predicate predicate = builder.and();
    // equal codeCategory
/*
    if (StringUtil.isNotEmpty( commentinfo.getCommentinfoType())) {
        predicate = builder.and(predicate, builder.like(
        builder.lower(root.<String>get(" commentinfoType")),
        LikePatternUtil.getLikePattern( commentinfo.getCommentinfoType())));
    }
  */

    if (StringUtil.isNotEmpty( commentinfo.getOpinion())) {
        predicate = builder.and(predicate, builder.like(
                builder.lower(root.<String>get("opinion")),
                LikePatternUtil.getLikePattern( commentinfo.getOpinion())));
    }
        return predicate;
        }
    };
    }


    }
